package View;

import java.awt.Dimension;
import java.util.Vector;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JPanel;

import Controller.CtrlSuppressionUtilisateur;
import Listener.LSuppression;

public class PanneauSupressionUtilisateur extends JPanel {
	private static final long serialVersionUID = 1L;
	private CtrlSuppressionUtilisateur Ctrl;
	private JComboBox<String> ComboBoxUser;
	
	public PanneauSupressionUtilisateur(CtrlSuppressionUtilisateur ctrl) {
		Ctrl = ctrl;
		JButton delete = new JButton("Delete");
		ComboBoxUser = new JComboBox<String>();

		ComboBoxUser.setPreferredSize(new Dimension(100, 20));
		
		delete.addActionListener(new LSuppression(ctrl));

		this.add(ComboBoxUser);
		this.add(delete);
		
		updateList();
	}
	
	public void updateList() {
		Vector<String> vector = new Vector<String>();
		
		for(int i = 0; i < Ctrl.getListeUser().nbUtilisateurs(); i++)
			vector.add(Ctrl.getListeUser().obtenirUtilisateur(i).getLogin());
		
		ComboBoxUser.setModel(new DefaultComboBoxModel<String>(vector));
		ComboBoxUser.revalidate();
		ComboBoxUser.repaint();
	}
	
	public int getSelected() {
		return ComboBoxUser.getSelectedIndex();
	}
	
}
